package com.xbongbong.pro.enums.teammembers.enums;

import com.xbongbong.paas.enums.PaySheetTypeEnum;
import com.xbongbong.paas.enums.PaymentSheetTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author: 汪腾伟
 * @date: Created in 2021/12/31 9:48
 * @description： 表单是否唯一枚举码
 */
@Getter
public enum FormOwnerUniqueEnum {
    /**
     * 客户管理
     */
    CUSTOMER_MANAGEMENT(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 联系人
     */
    CONTACT(XbbRefTypeEnum.CONTACT.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 销售机会
     */
    SALES_OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 报价单
     */
    QUOTATION(XbbRefTypeEnum.QUOTATION.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 合同订单
     */
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 退货退款
     */
    REFUND(XbbRefTypeEnum.REFUND.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 应收款
     */
    PAYMENT(XbbRefTypeEnum.PAYMENT.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 回款单
     */
    PAYMENT_SHEET(XbbRefTypeEnum.PAYMENT_SHEET.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 付款计划
     */
    PAY_PLAN(XbbRefTypeEnum.PAY_PLAN.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 付款单
     */
    PAY_SHEET(XbbRefTypeEnum.PAY_SHEET.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 供应商
     */
    SUPPLIER(XbbRefTypeEnum.SUPPLIER.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 供应商联系人
     */
    SUPPLIER_CONTACT(XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 采购合同
     */
    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 采购退货单
     */
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), OwnerUniqueDefaultEnum.UNIQUE.getValue()),

    /**
     * BOM清单
     */
    BOM_BILL(XbbRefTypeEnum.BOM_BILL.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 生产单
     */
    PRODUCTION_ORDER(XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 市场活动
     */
    MARKET_ACTIVITY(XbbRefTypeEnum.MARKET_ACTIVITY.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 线索
     */
    CLUE(XbbRefTypeEnum.CLUE.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 预收款
     */
    PAYMENT_BALANCE(XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * 预付款
     */
    PAY_BALANCE(XbbRefTypeEnum.PREPAY_BALANCE.getCode(), OwnerUniqueDefaultEnum.MULTIPLE.getValue()),

    /**
     * PAAS表单
     */
    PAAS_TEAM(XbbRefTypeEnum.SYSTEM.getCode(), OwnerUniqueDefaultEnum.UNIQUE.getValue()),

    WORK_ORDER_V2_TEAM(XbbRefTypeEnum.WORK_ORDER_V2.getCode(), OwnerUniqueDefaultEnum.UNIQUE.getValue()),
    RECEIPT_ORDER_TEAM(XbbRefTypeEnum.RECEIPT_ORDER.getCode(), OwnerUniqueDefaultEnum.UNIQUE.getValue()),

    ;

    /**
     * 业务类型
     */
    private Integer businessType;

    /**
     * 是否唯一标识
     */
    private Integer value;

    FormOwnerUniqueEnum(Integer businessType, Integer value) {
        this.businessType = businessType;
        this.value = value;
    }

    /**
     * 根据业务类型获取默认表单的负责人是否唯一
     *
     * @param businessType 业务类型
     * @return
     */
    public static FormOwnerUniqueEnum getFormOwnerUniqueByBus(Integer businessType) {
        List<Integer> allPaymentSheetBusinessTypes =  PaymentSheetTypeEnum.getAllBusinessType();
        List<Integer> allPaySheetBusinessTypes =  PaySheetTypeEnum.getAllBusinessType();
        if (allPaymentSheetBusinessTypes.contains(businessType)) {
            businessType = XbbRefTypeEnum.PAYMENT_SHEET.getCode();
        }
        if (allPaySheetBusinessTypes.contains(businessType)) {
            businessType = XbbRefTypeEnum.PAY_SHEET.getCode();
        }
        for (FormOwnerUniqueEnum formOwnerUniqueEnum : FormOwnerUniqueEnum.values()) {
            if (Objects.equals(businessType, formOwnerUniqueEnum.getBusinessType())) {
                return formOwnerUniqueEnum;
            }
        }
        return null;
    }

    /**
     * 获取有默认负责人设置的全部业务类型
    */
    public static List<Integer>  getDefaultBusinessList(){
        return Arrays.stream(FormOwnerUniqueEnum.values()).map(FormOwnerUniqueEnum::getBusinessType).collect(Collectors.toList());
    }


    public static List<Integer> getAllBusinessList() {
        List<Integer> allList = new ArrayList<>();
        for (FormOwnerUniqueEnum formOwnerUniqueEnum : FormOwnerUniqueEnum.values()) {
            allList.add(formOwnerUniqueEnum.getBusinessType());
        }
        return allList;
    }
}
